package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolTaskMoney;
import cn.stylefeng.guns.modular.tool.mapper.ToolTaskMoneyMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolTaskMoneyParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolTaskMoneyResult;
import  cn.stylefeng.guns.modular.tool.service.ToolTaskMoneyService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 计件明细 服务实现类
 */
@Service
public class ToolTaskMoneyServiceImpl extends ServiceImpl<ToolTaskMoneyMapper, ToolTaskMoney> implements ToolTaskMoneyService {

    @Override
    public void add(ToolTaskMoneyParam param){
        ToolTaskMoney entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolTaskMoneyParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolTaskMoneyParam param){
        ToolTaskMoney oldEntity = getOldEntity(param);
        ToolTaskMoney newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolTaskMoneyResult findBySpec(ToolTaskMoneyParam param){
        return null;
    }

    @Override
    public List<ToolTaskMoneyResult> findListBySpec(ToolTaskMoneyParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolTaskMoneyParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpecsum(ToolTaskMoneyParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListsum(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpecsum3(ToolTaskMoneyParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListsum3(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolTaskMoneyParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolTaskMoney getOldEntity(ToolTaskMoneyParam param) {
        return this.getById(getKey(param));
    }

    private ToolTaskMoney getEntity(ToolTaskMoneyParam param) {
        ToolTaskMoney entity = new ToolTaskMoney();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public void deleteBySpec(ToolTaskMoneyParam moneyParam) {
		this.baseMapper.deleteBySpec(moneyParam);
	}

	@Override
	public boolean saveBatchList(List<ToolTaskMoneyParam> listsave) {
		return this.baseMapper.saveBatchList(listsave);
	}

	@Override
	public void updateBySpec(ToolTaskMoneyParam param) {
		 this.baseMapper.updateBySpec(param);
	}

}
